package com.ruicar.afs.cloud.bizcommon.print.controller;

import com.ruicar.afs.cloud.bizcommon.dto.print.TemplateDto;
import com.ruicar.afs.cloud.bizcommon.print.entity.ComPrintFormFieldMapping;
import com.ruicar.afs.cloud.bizcommon.print.service.ComPrintFormFieldMappingService;
import com.ruicar.afs.cloud.common.core.query.QueryCondition;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * @author phong
 * @version 1.0
 * @description: 打印模板映射
 * @created 2020/6/19 11:38
 */
@Slf4j
@RestController
@AllArgsConstructor
@Api(value = "templateMapping", description = "模板映射管理")
@RequestMapping("/templateMapping")
public class ComPrintFormFieldMappingController {

    private ComPrintFormFieldMappingService comPrintFormFieldMappingService;

    @Transactional
    @PostMapping("/add")
    @ApiOperation(value = "新增字段映射")
    public IResponse<Boolean> add(@RequestBody @Validated ComPrintFormFieldMapping comPrintFormFieldMapping) throws ParseException {
        return IResponse.success(comPrintFormFieldMappingService.saveFieldMapping(comPrintFormFieldMapping));
    }

    @PostMapping("/edit")
    @ApiOperation(value = "编辑模板类别")
    public IResponse<Boolean> modifyTemplate(@RequestBody @Validated ComPrintFormFieldMapping comPrintFormFieldMapping) {
        return IResponse.success(comPrintFormFieldMappingService.modifyFieldMapping(comPrintFormFieldMapping));
    }

    @DeleteMapping("/del/{ids}")
    @ApiOperation(value = "删除模板映射")
    public IResponse<Boolean> delTemplate(@PathVariable String ids) {
        return IResponse.success(comPrintFormFieldMappingService.delFieldMapping(ids));
    }

    @PostMapping("/list")
    @ApiOperation(value = "查询模板映射列表")
    public IResponse queryTemplateList(@RequestBody QueryCondition<TemplateDto> queryCondition) {
        return comPrintFormFieldMappingService.query(queryCondition);
    }
}
